package com.eam.asset.assetApplication.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eam.asset.assetApplication.dto.AssetApplicationAddDto;
import com.eam.asset.assetApplication.dto.AssetApplicationDto;
import com.eam.asset.assetApplication.mapper.AssetApplicationMapper;
import com.eam.asset.file.utils.AssetEncode;
import com.eam.common.utils.DateUtils;
import com.eam.common.utils.SecurityUtils;
import com.eam.common.utils.bean.BeanUtils;
import com.eam.common.utils.uuid.IdUtils;
import org.springframework.stereotype.Service;
import com.eam.asset.assetApplication.domain.AssetApplication;
import com.eam.asset.assetApplication.service.IAssetApplicationService;

/**
 * 资产处置申请Service业务层处理
 *
 * @author tzf
 * @date 2023-10-31
 */
@Service
public class AssetApplicationServiceImpl extends ServiceImpl<AssetApplicationMapper, AssetApplication> implements IAssetApplicationService {


    /**
     * 查询资产处置申请
     *
     * @param id 资产处置申请主键
     * @return 资产处置申请
     */
    @Override
    public AssetApplication selectAssetApplicationById(String id) {
        //todo 考虑做缓存
        return baseMapper.selectById(id);
    }

    /**
     * 查询资产处置申请列表
     *
     * @param assetApplication 资产处置申请
     * @return 资产处置申请
     */
    @Override
    public List<AssetApplication> selectAssetApplicationList(AssetApplication assetApplication) {
        //todo 考虑做缓存
        return baseMapper.selectAssetApplicationList(assetApplication);
    }

    /**
     * 新增资产处置申请
     *
     * @param assetApplication 资产处置申请
     * @return 结果
     */
    @Override
    public int insertAssetApplication(AssetApplication assetApplication) {
        //创建dto对象,深拷贝属性值
        AssetApplicationAddDto assetApplicationAddDto = new AssetApplicationAddDto();
        BeanUtils.copyProperties(assetApplication, assetApplicationAddDto);
        //设置基本的信息
        assetApplicationAddDto.setId(IdUtils.simpleUUID());
        assetApplicationAddDto.setCreateBy(AssetEncode.IfAbsent(SecurityUtils.getUserId()));
        assetApplicationAddDto.setCreateTime(DateUtils.getNowDate());
        //设置资产档案编号,一级资产分类编码+二级资产分类编码+三级资产名称编码加日期时间
        return baseMapper.insert(assetApplicationAddDto);
    }

    /**
     * 修改资产处置申请
     *
     * @param assetApplication 资产处置申请
     * @return 结果
     */
    @Override
    public int updateAssetApplication(AssetApplication assetApplication) {
        assetApplication.setUpdateTime(DateUtils.getNowDate());
        assetApplication.setUpdateBy(AssetEncode.IfAbsent(SecurityUtils.getUserId()));
        AssetApplicationDto assetApplicationDto = new AssetApplicationDto();
        BeanUtils.copyProperties(assetApplication, assetApplicationDto);
        return baseMapper.updateById(assetApplicationDto);
    }

    /**
     * 批量删除资产处置申请
     *
     * @param ids 需要删除的资产处置申请主键
     * @return 结果
     */
    @Override
    public int deleteAssetApplicationByIds(String[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除资产处置申请信息
     *
     * @param id 资产处置申请主键
     * @return 结果
     */
    @Override
    public int deleteAssetApplicationById(String id) {
        return baseMapper.deleteById(id);
    }
}
